﻿namespace CommontLibrary
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Globalization;
    using System.Threading;
    /// <summary>
    /// Summary description for TranLanguage
    /// </summary>
    public class TranLanguage : System.Web.UI.Page
    {
        public TranLanguage()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        CultureInfo culture = null;
#region "Global Resources"
        //Tran All Page
        public void GlobalTranslateLanguage(object Page, string language)
        {
            Control objControl;
            string sID;
            string sDesc = "";
            ControlCollection objWebcontrol;
            try
            {
                culture = CultureInfo.CreateSpecificCulture(language);
                Thread.CurrentThread.CurrentUICulture = culture;
                Thread.CurrentThread.CurrentCulture = culture;
                objWebcontrol = (ControlCollection)Page;
                for (int i = 0; i < objWebcontrol.Count; i++)
                {
                    try
                    {
                        objControl = (Control)objWebcontrol[i];
                        switch (objControl.GetType().ToString())
                        {
                            case "System.Web.UI.WebControls.Button":
                                {
                                    sID = ((Button)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((Button)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.Label":
                                {
                                    sID = ((Label)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((Label)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.LinkButton":
                                {
                                    sID = ((LinkButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((LinkButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.TextBox":
                                {
                                    sID = ((TextBox)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((TextBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.HyperLink":
                                {
                                    sID = ((HyperLink)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((HyperLink)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.DropDownList":
                                {
                                    //sID = ((DropDownList)objControl).ID;
                                    //sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    //if (sDesc != "")
                                    //{
                                    //    ((DropDownList)objControl).Text = sDesc;
                                    //}
                                    break;
                                }
                            case "System.Web.UI.WebControls.RadioButton":
                                {
                                    sID = ((RadioButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RadioButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CheckBox":
                                {
                                    sID = ((CheckBox)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.HtmlControls.HtmlInputButton":
                                {
                                    sID = ((HtmlInputButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.GridView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    GlobalTranslateLanguageGridView(frvTran, language);
                                    break;
                                }
                            case "System.Web.UI.WebControls.FormView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    GlobalTranslateLanguage(objControl.Controls, language);
                                    break;
                                }
                            case "System.Web.UI.WebControls.RequiredFieldValidator":
                                {
                                    sID = ((RequiredFieldValidator)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RequiredFieldValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CustomValidator":
                                {
                                    sID = ((CustomValidator)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CustomValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            default:
                                GlobalTranslateLanguage(objControl.Controls, language);
                                break;

                        }
                    }
                    catch
                    {
                        //return false;
                    }
                }
            }
            catch
            {
                //return false;
            }
            finally
            {


            }
            //return true;
        }
        //Tran All Grid
        public void GlobalTranslateLanguageGridView(GridView frvTran, string language)
        {
            string sID;
            string sDesc = "";
            try
            {
                culture = CultureInfo.CreateSpecificCulture(language);
                Thread.CurrentThread.CurrentUICulture = culture;
                Thread.CurrentThread.CurrentCulture = culture;
                for (int i = 0; i < frvTran.Columns.Count; i++)
                {
                    try
                    {
                        DataControlField objControl = frvTran.Columns[i];
                        switch (objControl.GetType().ToString())
                        {
                            case "System.Web.UI.WebControls.TemplateField":
                                {
                                    sID = ((TemplateField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((TemplateField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.BoundField":
                                {
                                    sID = ((BoundField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((BoundField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CheckBoxField":
                                {
                                    sID = ((CheckBoxField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBoxField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.HyperLinkField":
                                {
                                    sID = ((HyperLinkField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((HyperLinkField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.ButtonField":
                                {
                                    sID = ((ButtonField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((ButtonField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CommandField":
                                {
                                    sID = ((CommandField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CommandField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.ImageField":
                                {
                                    sID = ((ImageField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((ImageField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            default:
                                //TranslateLanguageGridView(GridView frvTran, string language)
                                break;

                        }
                    }
                    catch
                    {
                        //return false;
                    }
                }
            }
            catch
            {
                //return false;
            }
            finally
            {


            }
            //return true;
        }
        //Tran All Page theo Object
        public void GlobalTranslateLanguageGridView(object Page, string language)
        {
            Control objControl;
            string sID;
            string sDesc = "";
            ControlCollection objWebcontrol;
            try
            {
                culture = CultureInfo.CreateSpecificCulture(language);
                Thread.CurrentThread.CurrentUICulture = culture;
                Thread.CurrentThread.CurrentCulture = culture;
                objWebcontrol = (ControlCollection)Page;
                for (int i = 0; i < objWebcontrol.Count; i++)
                {
                    try
                    {
                        objControl = (Control)objWebcontrol[i];
                        switch (objControl.GetType().ToString())
                        {
                            case "System.Web.UI.WebControls.Button":
                                {
                                    sID = ((Button)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((Button)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.Label":
                                {
                                    sID = ((Label)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((Label)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.LinkButton":
                                {
                                    sID = ((LinkButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((LinkButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.HyperLink":
                                {
                                    sID = ((HyperLink)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((HyperLink)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.DropDownList":
                                {
                                    //sID = ((DropDownList)objControl).ID;
                                    //sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    //if (sDesc != "")
                                    //{
                                    //    ((DropDownList)objControl).Text = sDesc;
                                    //}
                                    break;
                                }
                            case "System.Web.UI.WebControls.RadioButton":
                                {
                                    sID = ((RadioButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RadioButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CheckBox":
                                {
                                    sID = ((CheckBox)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.HtmlControls.HtmlInputButton":
                                {
                                    sID = ((HtmlInputButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.GridView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    GlobalTranslateLanguageGridView(frvTran, language);
                                    break;
                                }
                            case "System.Web.UI.WebControls.FormView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    GlobalTranslateLanguage(objControl.Controls, language);
                                    break;
                                }
                            case "System.Web.UI.WebControls.RequiredFieldValidator":
                                {
                                    sID = ((RequiredFieldValidator)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RequiredFieldValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CustomValidator":
                                {
                                    sID = ((CustomValidator)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject("Default", sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CustomValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            default:
                                GlobalTranslateLanguage(objControl.Controls, language);
                                break;

                        }
                    }
                    catch
                    {
                        //return false;
                    }
                }
            }
            catch
            {
                //return false;
            }
            finally
            {


            }
            //return true;
        }
        //Tran All Page Bien string
        public void GlobalTranslateLanguage(object Page, string language,string strFileName)
        {
            Control objControl;
            string sID;
            string sDesc = "";
            ControlCollection objWebcontrol;
            try
            {
                culture = CultureInfo.CreateSpecificCulture(language);
                Thread.CurrentThread.CurrentUICulture = culture;
                Thread.CurrentThread.CurrentCulture = culture;
                objWebcontrol = (ControlCollection)Page;
                for (int i = 0; i < objWebcontrol.Count; i++)
                {
                    try
                    {
                        objControl = (Control)objWebcontrol[i];
                        switch (objControl.GetType().ToString())
                        {
                            case "System.Web.UI.WebControls.Button":
                                {
                                    sID = ((Button)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((Button)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.TextBox":
                                {
                                    sID = ((TextBox)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((TextBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.Label":
                                {
                                    sID = ((Label)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((Label)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.LinkButton":
                                {
                                    sID = ((LinkButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((LinkButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.HyperLink":
                                {
                                    sID = ((HyperLink)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((HyperLink)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.DropDownList":
                                {
                                    //sID = ((DropDownList)objControl).ID;
                                    //sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    //if (sDesc != "")
                                    //{
                                    //    ((DropDownList)objControl).Text = sDesc;
                                    //}
                                    break;
                                }
                            case "System.Web.UI.WebControls.RadioButton":
                                {
                                    sID = ((RadioButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RadioButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CheckBox":
                                {
                                    sID = ((CheckBox)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.HtmlControls.HtmlInputButton":
                                {
                                    sID = ((HtmlInputButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.GridView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    GlobalTranslateLanguageGridView(frvTran, language, strFileName);
                                    break;
                                }
                            case "System.Web.UI.WebControls.FormView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    GlobalTranslateLanguage(objControl.Controls, language, strFileName);
                                    break;
                                }
                            case "System.Web.UI.WebControls.RequiredFieldValidator":
                                {
                                    sID = ((RequiredFieldValidator)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RequiredFieldValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CustomValidator":
                                {
                                    sID = ((CustomValidator)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CustomValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            default:
                                GlobalTranslateLanguage(objControl.Controls, language, strFileName);
                                break;

                        }
                    }
                    catch
                    {
                        //return false;
                    }
                }
            }
            catch
            {
                //return false;
            }
            finally
            {


            }
            //return true;
        }
        //Tran All Grid
        public void GlobalTranslateLanguageGridView(GridView frvTran, string language, string strFileName)
        {
            string sID;
            string sDesc = "";
            try
            {
                culture = CultureInfo.CreateSpecificCulture(language);
                Thread.CurrentThread.CurrentUICulture = culture;
                Thread.CurrentThread.CurrentCulture = culture;
                for (int i = 0; i < frvTran.Columns.Count; i++)
                {
                    try
                    {
                        DataControlField objControl = frvTran.Columns[i];
                        switch (objControl.GetType().ToString())
                        {
                            case "System.Web.UI.WebControls.TemplateField":
                                {
                                    sID = ((TemplateField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((TemplateField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.BoundField":
                                {
                                    sID = ((BoundField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((BoundField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CheckBoxField":
                                {
                                    sID = ((CheckBoxField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBoxField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.HyperLinkField":
                                {
                                    sID = ((HyperLinkField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((HyperLinkField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.ButtonField":
                                {
                                    sID = ((ButtonField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((ButtonField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CommandField":
                                {
                                    sID = ((CommandField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CommandField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.ImageField":
                                {
                                    sID = ((ImageField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((ImageField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            default:
                                //TranslateLanguageGridView(GridView frvTran, string language)
                                break;

                        }
                    }
                    catch
                    {
                        //return false;
                    }
                }
            }
            catch
            {
                //return false;
            }
            finally
            {


            }
            //return true;
        }
        //Tran All Grid theo Object
        public void GlobalTranslateLanguageGridView(object Page, string language, string strFileName)
        {
            Control objControl;
            string sID;
            string sDesc = "";
            ControlCollection objWebcontrol;
            try
            {
                culture = CultureInfo.CreateSpecificCulture(language);
                Thread.CurrentThread.CurrentUICulture = culture;
                Thread.CurrentThread.CurrentCulture = culture;
                objWebcontrol = (ControlCollection)Page;
                for (int i = 0; i < objWebcontrol.Count; i++)
                {
                    try
                    {
                        objControl = (Control)objWebcontrol[i];
                        switch (objControl.GetType().ToString())
                        {
                            case "System.Web.UI.WebControls.Button":
                                {
                                    sID = ((Button)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((Button)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.Label":
                                {
                                    sID = ((Label)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((Label)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.LinkButton":
                                {
                                    sID = ((LinkButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((LinkButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.HyperLink":
                                {
                                    sID = ((HyperLink)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((HyperLink)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.DropDownList":
                                {
                                    //sID = ((DropDownList)objControl).ID;
                                    //sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    //if (sDesc != "")
                                    //{
                                    //    ((DropDownList)objControl).Text = sDesc;
                                    //}
                                    break;
                                }
                            case "System.Web.UI.WebControls.RadioButton":
                                {
                                    sID = ((RadioButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RadioButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CheckBox":
                                {
                                    sID = ((CheckBox)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.HtmlControls.HtmlInputButton":
                                {
                                    sID = ((HtmlInputButton)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.GridView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    GlobalTranslateLanguageGridView(frvTran, language, strFileName);
                                    break;
                                }
                            case "System.Web.UI.WebControls.FormView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    GlobalTranslateLanguage(objControl.Controls, language, strFileName);
                                    break;
                                }
                            case "System.Web.UI.WebControls.RegularExpressionValidator":
                                {
                                    sID = ((RegularExpressionValidator)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RegularExpressionValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.RequiredFieldValidator":
                                {
                                    sID = ((RequiredFieldValidator)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RequiredFieldValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CustomValidator":
                                {
                                    sID = ((CustomValidator)objControl).ID;
                                    sDesc = this.GetGlobalResourceObject(strFileName, sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CustomValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            default:
                                GlobalTranslateLanguage(objControl.Controls, language, strFileName);
                                break;

                        }
                    }
                    catch
                    {
                        //return false;
                    }
                }
            }
            catch
            {
                //return false;
            }
            finally
            {


            }
            //return true;
        }
#endregion

#region "Local Resources"
        //Tran All Page
        public void LocalTranslateLanguage(object Page, string language)
        {
            Control objControl;
            string sID;
            string sDesc = "";
            ControlCollection objWebcontrol;
            try
            {
                culture = CultureInfo.CreateSpecificCulture(language);
                Thread.CurrentThread.CurrentUICulture = culture;
                Thread.CurrentThread.CurrentCulture = culture;
                objWebcontrol = (ControlCollection)Page;
                for (int i = 0; i < objWebcontrol.Count; i++)
                {
                    try
                    {
                        objControl = (Control)objWebcontrol[i];
                        switch (objControl.GetType().ToString())
                        {
                            case "System.Web.UI.WebControls.Button":
                                {
                                    sID = ((Button)objControl).ID;
                                    sDesc = this.GetLocalResourceObject(sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((Button)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.Label":
                                {
                                    sID = ((Label)objControl).ID;
                                    sDesc = Convert.ToString(this.GetLocalResourceObject(sID));
                                    if (sDesc != "")
                                    {
                                        ((Label)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.LinkButton":
                                {
                                    sID = ((LinkButton)objControl).ID;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((LinkButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.HyperLink":
                                {
                                    sID = ((HyperLink)objControl).ID;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((HyperLink)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.DropDownList":
                                {
                                    //sID = ((DropDownList)objControl).ID;
                                    //sDesc = this.GetLocalResourceObject( sID).ToString();
                                    //if (sDesc != "")
                                    //{
                                    //    ((DropDownList)objControl).Text = sDesc;
                                    //}
                                    break;
                                }
                            case "System.Web.UI.WebControls.RadioButton":
                                {
                                    sID = ((RadioButton)objControl).ID;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RadioButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CheckBox":
                                {
                                    sID = ((CheckBox)objControl).ID;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.HtmlControls.HtmlInputButton":
                                {
                                    sID = ((HtmlInputButton)objControl).ID;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.GridView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    LocalTranslateLanguageGridView(frvTran, language);
                                    break;
                                }
                            case "System.Web.UI.WebControls.FormView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    LocalTranslateLanguage(objControl.Controls, language);
                                    break;
                                }
                            case "System.Web.UI.WebControls.RequiredFieldValidator":
                                {
                                    sID = ((RequiredFieldValidator)objControl).ID;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RequiredFieldValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CustomValidator":
                                {
                                    sID = ((CustomValidator)objControl).ID;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CustomValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.RegularExpressionValidator":
                                {
                                    sID = ((RegularExpressionValidator)objControl).ID;
                                    sDesc = this.GetLocalResourceObject(sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RegularExpressionValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            default:
                                LocalTranslateLanguage(objControl.Controls, language);
                                break;

                        }
                    }
                    catch 
                    {
                        //return false;
                    }
                }
            }
            catch
            {
                //return false;
            }
            finally
            {


            }
            //return true;
        }
        //Tran All Grid
        public void LocalTranslateLanguageGridView(GridView frvTran, string language)
        {
            string sID;
            string sDesc = "";
            try
            {
                culture = CultureInfo.CreateSpecificCulture(language);
                Thread.CurrentThread.CurrentUICulture = culture;
                Thread.CurrentThread.CurrentCulture = culture;
                for (int i = 0; i < frvTran.Columns.Count; i++)
                {
                    try
                    {
                        DataControlField objControl = frvTran.Columns[i];
                        switch (objControl.GetType().ToString())
                        {
                            case "System.Web.UI.WebControls.TemplateField":
                                {
                                    sID = ((TemplateField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((TemplateField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.BoundField":
                                {
                                    sID = ((BoundField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((BoundField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CheckBoxField":
                                {
                                    sID = ((CheckBoxField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBoxField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.HyperLinkField":
                                {
                                    sID = ((HyperLinkField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((HyperLinkField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.ButtonField":
                                {
                                    sID = ((ButtonField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((ButtonField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CommandField":
                                {
                                    sID = ((CommandField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CommandField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.ImageField":
                                {
                                    sID = ((ImageField)objControl).AccessibleHeaderText;
                                    sDesc = this.GetLocalResourceObject( sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((ImageField)objControl).HeaderText = sDesc;
                                    }
                                    break;
                                }
                            default:
                                //TranslateLanguageGridView(GridView frvTran, string language)
                                break;

                        }
                    }
                    catch
                    {
                        //return false;
                    }
                }
            }
            catch
            {
                //return false;
            }
            finally
            {


            }
            //return true;
        }
        //Tran All Grid theo Object
        public void LocalTranslateLanguageGridView(object Page, string language)
        {
            Control objControl;
            string sID;
            string sDesc = "";
            ControlCollection objWebcontrol;
            try
            {
                culture = CultureInfo.CreateSpecificCulture(language);
                Thread.CurrentThread.CurrentUICulture = culture;
                Thread.CurrentThread.CurrentCulture = culture;
                objWebcontrol = (ControlCollection)Page;
                for (int i = 0; i < objWebcontrol.Count; i++)
                {
                    try
                    {
                        objControl = (Control)objWebcontrol[i];
                        switch (objControl.GetType().ToString())
                        {
                            case "System.Web.UI.WebControls.Button":
                                {
                                    sID = ((Button)objControl).ID;
                                    sDesc = this.GetLocalResourceObject(sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((Button)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.Label":
                                {
                                    sID = ((Label)objControl).ID;
                                    sDesc = Convert.ToString(this.GetLocalResourceObject(sID));
                                    if (sDesc != "")
                                    {
                                        ((Label)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.LinkButton":
                                {
                                    sID = ((LinkButton)objControl).ID;
                                    sDesc = this.GetLocalResourceObject(sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((LinkButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.HyperLink":
                                {
                                    sID = ((HyperLink)objControl).ID;
                                    sDesc = this.GetLocalResourceObject(sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((HyperLink)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.DropDownList":
                                {
                                    //sID = ((DropDownList)objControl).ID;
                                    //sDesc = this.GetLocalResourceObject( sID).ToString();
                                    //if (sDesc != "")
                                    //{
                                    //    ((DropDownList)objControl).Text = sDesc;
                                    //}
                                    break;
                                }
                            case "System.Web.UI.WebControls.RadioButton":
                                {
                                    sID = ((RadioButton)objControl).ID;
                                    sDesc = this.GetLocalResourceObject(sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RadioButton)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CheckBox":
                                {
                                    sID = ((CheckBox)objControl).ID;
                                    sDesc = this.GetLocalResourceObject(sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.HtmlControls.HtmlInputButton":
                                {
                                    sID = ((HtmlInputButton)objControl).ID;
                                    sDesc = this.GetLocalResourceObject(sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CheckBox)objControl).Text = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.GridView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    LocalTranslateLanguageGridView(frvTran, language);
                                    break;
                                }
                            case "System.Web.UI.WebControls.FormView":
                                {
                                    GridView frvTran = ((GridView)objControl);
                                    sID = frvTran.ID;
                                    LocalTranslateLanguage(objControl.Controls, language);
                                    break;
                                }
                            case "System.Web.UI.WebControls.RequiredFieldValidator":
                                {
                                    sID = ((RequiredFieldValidator)objControl).ID;
                                    sDesc = this.GetLocalResourceObject(sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((RequiredFieldValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            case "System.Web.UI.WebControls.CustomValidator":
                                {
                                    sID = ((CustomValidator)objControl).ID;
                                    sDesc = this.GetLocalResourceObject(sID).ToString();
                                    if (sDesc != "")
                                    {
                                        ((CustomValidator)objControl).ErrorMessage = sDesc;
                                    }
                                    break;
                                }
                            default:
                                LocalTranslateLanguage(objControl.Controls, language);
                                break;

                        }
                    }
                    catch 
                    {
                        //return false;
                    }
                }
            }
            catch
            {
                //return false;
            }
            finally
            {


            }
            //return true;
        }
#endregion
    }
}